package com.longge;

import java.util.HashMap;
import java.util.Map;

public class CountBalls {

    public int countBalls(int lowLimit, int highLimit) {

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = lowLimit; i <= highLimit; i++) {
            char[] chars = String.valueOf(i).toCharArray();
            int num = 0;
            for (char aChar : chars) {
                int a = aChar - '0';
                num += a;
            }
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int max = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            max  = Math.max(entry.getValue(),max);
        }
        return max;
    }
}
